package org.noote.libs.sogle.helper;

import org.noote.libs.sogle.Mesh;

import android.util.FloatMath;

public class Mesh_Circle extends Mesh {
	
	public Mesh_Circle(float fDiameter, int iSlice) {

		fDiameter /=2;
		iSlice = iSlice<2?2:iSlice;
		
		float[] vertices = new float[(iSlice+1+1)*3];
		short[] indices = new short[(iSlice)*3];
		
		vertices[0] = 0;
		vertices[1] = 0;
		vertices[2] = 0;
		
		float fSliceSize = (float) ((Math.PI*2)/iSlice);
		for(int s=0; s<iSlice+1; s++)
		{
			int idx = (s+1)*3;
			vertices[idx + 0] = FloatMath.cos(fSliceSize*s)*fDiameter;
			vertices[idx + 1] = 0;
			vertices[idx + 2] = FloatMath.sin(fSliceSize*s)*fDiameter;
		}
		
		for(int s=0; s<iSlice; s++)
		{
			int idx = s*3;
			
			// Triangle 1
			indices[idx + 0] = (short) (0);
			indices[idx + 1] = (short) (s+1+1);
			indices[idx + 2] = (short) (s+1);
		}
		
		setIndices(indices);
		setVertices(vertices);
		generateNormales();
	}
}
